#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#define SIZE 256
#define MAX_ARGC 16

char *argv[MAX_ARGC];

void mysys(char *command) {
    char line[SIZE];
    strcpy(line, command);

    int argc = 0;
    for(int i = 0; i < MAX_ARGC; i++)
    argv[i] = NULL;

    char *word;
    char *delim = " \n";
    word = strtok(line, delim);
    while(word != NULL) {
      argv[argc] = word;
      word = strtok(NULL, delim);
      argc++;
    }


    pid_t pid;
    pid = fork();
    if(pid == 0) {
      int error = execvp(argv[0], argv);
      if(error < 0)
        perror("execvp");
    }
    wait(NULL);
}

int main() {
    printf("--------------------------------------------------\n");
    mysys("echo HELLO WORLD");
    printf("--------------------------------------------------\n");
    mysys("ls /");
    printf("--------------------------------------------------\n");
    return 0;
}

